<?php if ( ! defined('BASEPATH')) exit('No direct script access allowed');

session_start();

class Upload_foto extends CI_Controller {    
public function __construct() {
    parent::__construct();   
}       
public function index(){
    
    $this->load->model('m_uploadfoto');
    $error = array('error' => '');
    $data2 ["content"] = $this->load->view('absensi/file_view',$error,true);
    $this->load->view('absensi/mainUser',$data2);    
}



public function save()
{
    $this->load->model('m_uploadfoto');
    $id_user = $this->session->userdata('id');
    $url = $this->do_upload();
    $this->m_uploadfoto->save($url,$id_user);
   
  redirect ('upload_foto/selesai');
}


private function do_upload(){
    
    $type = explode('.', $_FILES["userfile"]["name"]);
    $type = $type[count($type)-1];
    
    $url = "./images/".uniqid(rand()).'.'.$type;
    
    if (is_uploaded_file($_FILES["userfile"]["tmp_name"]))         
        if (move_uploaded_file($_FILES["userfile"]["tmp_name"],$url))
            return $url;
    return "";

}

public function selesai()
{
   $data = $this->load->model('m_uploadfoto');
   $data2["content"] = $this->load->view('absensi/upload_success',$data,true);
   $this->load->view("absensi/mainUser",$data2);
}



    
}
?>